import '@babel/polyfill';
import * as THREE from 'three';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';
import gsap from 'gsap';
import * as dat from 'dat.gui';
import { DoubleSide } from 'three';

//场景
const scene = new THREE.Scene();

//相机
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 200);
camera.position.set(0, 0, 0.1);
scene.add(camera);

//渲染器
const renderer = new THREE.WebGL1Renderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

//数组每个面颜色贴图（全景看房）
const textureLoader=new THREE.TextureLoader();
const cubeMaterialArry=[];
for(let i=1;i<7;i++){
    const texture=textureLoader.load(`./textures/environmentMaps/0/${i}.jpg`);
    const cubeMaterial=new THREE.MeshBasicMaterial({
        map:texture,
    });
    cubeMaterialArry.push(cubeMaterial);
};

//mesh
const cubeGoemetry=new THREE.BoxGeometry(10,10,10);
const cube=new THREE.Mesh(cubeGoemetry,cubeMaterialArry);
cubeGoemetry.scale(-1,1,1);//实现内外翻转
cube.scale.set(1,1,-1);//y轴翻转
cube.position.set(0,0,0);
scene.add(cube);





//控制
const orbitControls = new OrbitControls(camera, renderer.domElement);
orbitControls.enableDamping = true;

//坐标轴
const axesHelper = new THREE.AxesHelper(5);
scene.add(axesHelper);


//帧动画
function animate() {
    orbitControls.update();
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
};
animate();

//窗口调整侦听
window.addEventListener('resize', () => {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setPixelRatio(window.devicePixelRatio);
});



